# -*- coding: utf-8 -*-
import sys
import jieba
import re

class UserData:
    def __init__(self, ahtc, grjn, shsjjljrzqk, hjjfbzpqk, zykyhdhxshd, grzjhqzyj):
        self.ahtc = ahtc
        self.grjn = grjn
        self.shsjjljrzqk = shsjjljrzqk
        self.hjjfbzpqk = hjjfbzpqk
        self.zykyhdhxshd = zykyhdhxshd
        self.grzjhqzyj = grzjhqzyj

    def process_data(self):
        keywords = ['制作', '写作', '工作', '运营', '公众', '视频剪辑', '语言', '微信', '视频', '编辑', '分析', '经验']

        # 计算每个关键词集合的最大得分
        max_score = len(keywords)
        # 为每条文本计算得分
        score = score_text(self.grjn, keywords)
        # 归一化得分
        normalized_score = (score / max_score) * 5 if max_score > 0 else 0
        return normalized_score


# 文本预处理函数
def prepare_text(text):
    stopwords = ['年月日']
    words = jieba.lcut(text)
    words = [word for word in words if len(word) > 1]
    words = [word for word in words if word not in stopwords]
    content = ' '.join(words)
    content = ' '.join(re.findall('[\u4e00-\u9fa5]+', content))
    return content


# 关键词匹配得分函数
def score_text(text, keywords):
    # 预处理文本
    processed_text = prepare_text(text)
    # 分词
    words = jieba.lcut(processed_text)
    # 初始化得分
    score = 0
    # 遍历关键词，统计出现频率并计算得分
    for keyword in keywords:
        score += words.count(keyword)
    return score


# 运行主函数
if __name__ == "__main__":
    # 从命令行参数中获取字符串数据
    grjn = sys.argv[1]
    # 创建 UserData 类的实例
    user_data = UserData('ahtc', grjn, 'shsjjljrzqk', 'hjjfbzpqk', 'zykyhdhxshd', 'grzjhqzyj')
    # 处理用户数据
    result = user_data.process_data()
    # 打印结果
    print(f"{result:.2f}")  # 打印第一个得分，保留两位小数
